import store from '@/store'
import Vue from 'vue'
const that = new Vue()
// 跳转这些路由时候，缓存当前路由的上一个路由
const path = ['/details']
const keepAlive = (to, from, next) => {
  // 跳转这些路由时候，缓存当前路由的上一个路由
  if (path.includes(to.path)) {
    // 组件名一定要写
    store.commit('SET_CATCHE_COMPONENTS', from.name)
  } else {
    store.commit('DEL_CATCHE_COMPONENTS', from.name)
  }
  // console.log(store.state.keepAlive.catchComponents, 'keepAlive')
  // 防止第二次进来时keepAlive失效
  that.$nextTick(() => { next() })
}
export default {
  beforeRouteLeave (to, from, next) {
    keepAlive(to, from, next)
  }
}
